import store from '@/store/index.js';
var FormDesignerUtil= function() {

};

FormDesignerUtil.prototype.componentClickHandler = function(component) {
	if(store.state.formDesigner.getSelectedDesignComponent()!=null){
		store.state.formDesigner.getSelectedDesignComponent().setSelected(false);
	}
	store.state.formDesigner.setSelectedDesignComponent(component);
	component.setSelected(true);
    store.state.formDesigner.getPropertyTable().setSelectedComponent(component);
}

FormDesignerUtil.prototype.mobileComponentClickHandler = function(component) {
	if (store.state.mformDesigner.getSelectedDesignComponent() != null) {
		store.state.mformDesigner.getSelectedDesignComponent().setSelected(false);
	}
	store.state.mformDesigner.setSelectedDesignComponent(component);
	component.setSelected(true);
	store.state.mformDesigner.getPropertyTable().setSelectedComponent(component);
}

FormDesignerUtil.prototype.setComponentModelPropValue=function(componentModel,prop,value){
	componentModel[prop]=value;
}

FormDesignerUtil.prototype.getComponentModelPropValue=function(componentModel,prop){
	return componentModel[prop];
}

FormDesignerUtil.prototype.setComponentModelDefaultFieldValues=function(componentModel){
	if(componentModel.col==undefined){
		componentModel.col=2;
	}
	if(componentModel.labelExpression==undefined){
		componentModel.labelExpression="标签";
	}
	if(componentModel.noLabel==undefined){
		componentModel.noLabel=false;
	}
	if(componentModel.noLabel==true){
		componentModel.col=4;
		componentModel.fieldcol=24;
	}else{
		componentModel.fieldcol=16;
	}
}

FormDesignerUtil.prototype.setComponentModelCommonValue=function(componentModel,prop,value){
	var propertyMap = componentModel["propertyMap"];
	if (propertyMap == undefined) {
		propertyMap = {};
		this.componentModel["propertyMap"] = propertyMap;
	}
	propertyMap[prop] = value;
}

FormDesignerUtil.prototype.getComponentModelCommonValue=function(componentModel,prop){
	var propertyMap = componentModel["propertyMap"];
	if (propertyMap == undefined) {
		this.componentModel["propertyMap"] = {};
		return undefined;
	}
	var value = propertyMap[prop];
	return value;
}

FormDesignerUtil.prototype.clearChildren=function(componentModel){
	componentModel.children=[];
}

export default new FormDesignerUtil();